package com.hdoit.ares.web.ser.wechat;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hdoit.ares.logical.ser.model.GoodsService;
import com.hdoit.ares.logical.ser.service.IGoodsServiceService;
import com.tennetcn.common.logical.setting.model.ParamOption;
import com.tennetcn.component.wechat.BaseWechat;

@Controller
@RequestMapping(value="/wechat/ser/serIndex/")
public class ServiceIndexWechat extends BaseWechat{
	
	@Override
	public String getRoutePath() {
		
		return "areas/wechat/ser/serIndex/";
	}
	
	
	private IGoodsServiceService goodsServiceService;
	
	public IGoodsServiceService getGoodsServiceService() {
		return goodsServiceService;
	}

	@Resource
	public void setGoodsServiceService(IGoodsServiceService goodsServiceService) {
		this.goodsServiceService = goodsServiceService;
	}
	
	private final String serIndexViewName = "service";
	private final String secondMenuViewName = "secondMenu";
	private final String goodsViewName = "goods";
	private final String goodDetailViewName = "goodDetail";
	
	@RequestMapping(value = serIndexViewName,method = {RequestMethod.GET,RequestMethod.POST})
	public String serIndex(Model model){
		List<ParamOption>serviceTypeNames = goodsServiceService.queryAllServiceTypeName("serviceTypeName");
		model.addAttribute("serviceTypeNames", serviceTypeNames);
	
		return view(serIndexViewName);
	}
	
	@RequestMapping(value = secondMenuViewName, method = { RequestMethod.GET })
	public String secondMenu(Model model,String parentId,String forId){
		List<ParamOption>options = goodsServiceService.queryList(parentId);
		model.addAttribute("options", options);	
		model.addAttribute("forId", forId);
		return view(secondMenuViewName);
	}
	
	@RequestMapping(value = goodsViewName, method = { RequestMethod.GET })
	public String goods(Model model,String serviceTypeName,String serviceName){
		List<GoodsService> goods = goodsServiceService.queryFirstGoods(serviceTypeName, serviceName,"1");
		model.addAttribute("goods", goods);
		return view(goodsViewName);
	}
	
	@RequestMapping(value = goodDetailViewName,method = {RequestMethod.GET,RequestMethod.POST})
	public String detail(Model model,String goodId,String fromWhere){
		GoodsService goodsService = goodsServiceService.selectModelById(goodId);
		
		model.addAttribute("goodsService", goodsService);
		model.addAttribute("fromWhere", fromWhere);
		
		return view(goodDetailViewName);
	}
	
	
}

